package cn.herlioner.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import cn.herlioner.dao.PermissionsDAO;
import cn.herlioner.pojo.Permissions;

public class PermissionsDAOImpl implements PermissionsDAO{

	@Override
	public void add(Permissions i) {
		SessionFactory sf = new Configuration().configure()
				.buildSessionFactory();
		Session s = sf.openSession();
		s.beginTransaction();
		
		s.save(i);
		
		s.getTransaction().commit();
		s.close();
		sf.close();
	}

	@Override
	public List<Permissions> list() {
		List<Permissions> result = new ArrayList();
		 
        SessionFactory sf = new Configuration().configure()
                .buildSessionFactory();
        Session s = sf.openSession();
 
        Query q = s.createQuery("from Permissions p");
 
        result = q.list();
 
        s.close();
        sf.close();
        return result;
	}

	@Override
	public List<Permissions> getListByPermissions(String i) {
		List<Permissions> result = new ArrayList();
		SessionFactory sf = new Configuration().configure()
				.buildSessionFactory();
		Session s = sf.openSession();
		Query q = s.createQuery("from Permissions where PERMISSIONSS = :PERMISSIONSS").setString("PERMISSIONSS",i );
		result = q.list();
		s.close();
		sf.close();
		return result;
	}

}
